<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>宠物表单</title>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="../../../plugins/element-ui/index.css">
    <!--    上传图片样式-->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
</head>
<body>
<div id="app">

    <el-container style="height: 800px; border: 1px solid #eee">
        <el-container>
            <div style="width: 100%;position: relative">

                <div style=";margin-bottom: 80px;">
                    <el-input
                            placeholder="请输入订单号"
                            clearable
                            style="width: 20%; "
                            prefix-icon="el-icon-search"
                            v-model="Query.orderNumber"
                    >
                    </el-input>
                    <el-button @click="getAll()" class="dalfBut">查询</el-button>
                </div>

                <!--1.数据展示-->
                <el-table   size="medium" current-row-key="id"  :data="dataList" stripe highlight-current-row>
                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                    <el-table-column prop="userId" label="用户名ID" align="center"></el-table-column>
                    <el-table-column prop="dishId" label="菜品ID" align="center"></el-table-column>
                    <el-table-column prop="image" label="图片" align="center">
                        <template slot-scope="{ row }">
                            <img style="width: auto; height: 2px; border:none;cursor: pointer;"
                                 :preview-src-list=" `/files/downloadFile?name=${row.image}` "
                                 :src="getImage(row.image)"
                            />
                            <div slot="error" class="image-slot">
                                <img :src="imageUrl1"  style="width: auto; height: 40px; border:none;" >
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="number" label="数量" align="center"></el-table-column>
                    <el-table-column prop="price" label="单价" align="center"></el-table-column>
                    <el-table-column prop="total" label="总价" align="center"></el-table-column>
                    <el-table-column prop="remarks" label="备注" align="center"></el-table-column>
                    <el-table-column prop="time" label="下单时间" align="center"></el-table-column>
                    <el-table-column prop="orderNumber" label="订单号" align="center"></el-table-column>


                </el-table>
                <!--分页组件-->
                <el-pagination
                        class="pagination"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>


            </div>
        </el-container>
    </el-container>

</div>


<script src="../../../plugins/vue/vue.js"></script>

<!-- 引入element-ui组件库 -->
<script src="../../../plugins/element-ui/index.js"></script>

<!-- 引入axios -->
<script src="../../../plugins/axios/axios.min.js"></script>

<script>
    new Vue({
        el:'#app',    //element
        data:{
            Query:{
                orderNumber:"",
            },

            //显示的数据
            dataList:[],

            //element-ui分页插件
            pagination: {//分页相关模型数据 1
                currentPage: 1,//当前页码1
                pageSize:5,//每页显示的记录数1
                total:0,//总记录数1
            },
            imageUrl:'',

        },
        created() {
            this.getAll();
        },
        methods:{
            getAll(){
                parent ="?orderNumber="+this.Query.orderNumber;

                axios.get("/ordersLists/getPageOrdersList/"+this.pagination.currentPage+"/"+this.pagination.pageSize+parent).then((res)=>{

                    console.log("res:")
                    console.log(res)

                    this.dataList=res.data.data.records
                    this.pagination.total=res.data.data.total
                    for (var i = 0; i < this.dataList.length; i++) {
                        this.dataList[i].time=this.replace(this.dataList[i].time,"yyyy-MM-dd hh:mm:ss")
                    }
                    this.Query.orderNumber=""

                })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                console.log("切换页码:")
                this.pagination.currentPage=currentPage;
                console.log(currentPage)
                this.getAll();
            },
            //将时间戳变成想要的格式（yyyy-MM-dd hh:mm:ss）
            replace(date, str) {
                var time = new Date(date);
                var y = time.getFullYear();
                var M = time.getMonth() + 1;
                var d = time.getDate();
                var h = time.getHours();
                var m = time.getMinutes();
                var s = time.getSeconds();
                var result =  str.replace(/(y+)/g, y).replace(/(M+)/g, M).replace(/(d+)/g, d).replace(/(h+)/g, h).replace(/(m+)/g, m).replace(/(s+)/g, s);
                return result;
            },

            getImage (image) {
                this.imageUrl1= `/files/downloadFile?name=${image}`
            },


        }
    })

</script>
</body>
</html>